package xmlServer;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

import xml.ReadXML;

public class XMLServer {

	
	public static void main(String[] args) {
		PrintWriter out = null;
		BufferedReader in = null;
	
	
			  ServerSocket serverSocket = null;
			  try {
				  serverSocket = new ServerSocket(64567);
				} 
				catch (IOException e) {
				    System.out.println("Could not listen on port: 64567");
				    System.exit(-1);
				}
			  Socket clientSocket = null;
			  try {
			      clientSocket = serverSocket.accept();
			      
			      out = new PrintWriter(clientSocket.getOutputStream(), true);
				  in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
				
				  
				  
			
				  File f = new File("docasny.xml");
				  f.createNewFile();
				  FileWriter fw = new FileWriter("docasny.xml");
				  
				 
				  int c;
			      while (in.ready()) {
			           fw.write(in.readLine());
			      }
				  
			      fw.close();
			      
			      ReadXML r = new ReadXML();
			      r.reader();
			      
				  out.close();
				  in.close();
				  clientSocket.close();
				  serverSocket.close();
			  } 
			  catch (IOException e) {
				  e.printStackTrace();
			      System.out.println("Accept failed: 64567");
			      System.exit(-1);
			  }
			  
			  
			 
		 }
	}
